﻿using Inovout.Cloud.DataWarehouse.Models;
using Inovout.Cloud.DataWarehouse.Repositories;
using Inovout.Services;
using NHibernate.Criterion;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Inovout.Cloud.DataWarehouse.Services
{
    public class DataCollectionService : RepositoryService<DataCollection>, IDataCollectionService
    {
        protected DataCollectionRepository DataCollectionRepository
        {
            get
            {
                return (DataCollectionRepository)base.Repository;
            }
        }

        public void Delete(string dataCollectionName)
        {
            DataCollection dataCollection = FindByName(dataCollectionName);
            
            if (dataCollection != null)
            {
            //    base.Delete((object)dataCollection.Id);
                DataCollectionRepository.Delete(dataCollection);
            }
        }

        public DataCollection FindByName(string dataCollectionName)
        {
            return base.Repository.Find(Restrictions.Eq("Name", dataCollectionName).IgnoreCase());
        }

        public IEnumerable<DataCollection> FindAll()
        {
            return base.FindAll();
        }

        public void SaveDataCollectionViewTemplate(DataCollectionViewTemplate dataCollectionViewTemplate) {
            DataCollectionRepository.SaveDataCollectionViewTemplate(dataCollectionViewTemplate);
        }
    }
}
